#include <iostream>
#include <stack>

const int N = 10;

using namespace std;
//双栈模拟队列 进行入队操作
bool enterqueue(stack<int> &s1, stack<int> &s2, int x)
{
    if (s1.size() < N)
    {
        s1.push(x);
        return true;
    }
    else if (s1.size() == N && !s2.empty())
        return false;
    else if (s1.size() == N && s2.empty())
    {
        while (!s1.empty())
        {
            s2.push(s1.top());
            s1.pop();
        }
    }
    s1.push(x);
    return true;
}
//模拟出队操作
bool outqueue(stack<int> &s1, stack<int> &s2, int &x)
{
    if (!s2.empty())
    {
        x = s2.top();
        s2.pop();
        return true;
    }
    //    s1,s2都空了 出队失败
    else if (s1.empty())
        return false;
    else if (s2.empty() && !s1.empty())
    {
        while (!s1.empty())
        {
            s2.push(s1.top());
            s1.pop();
        }
    }
    x = s2.top();
    s2.pop();
    return false;
}
int main()
{
    stack<int> s1, s2;
    //    cout<<s1.size()<<" "<<s1.empty()<<endl;
    for (int i = 0; i < N; i++)
        enterqueue(s1, s2, i);
    int temp = 0;
    for (int i = 0; i < N; i++)
        if (outqueue(s1, s2, temp))
            cout << temp << " ";
    return 0;
}